//导入request.js请求工具
import request from '@/utils/request.js'

//消息类型集
export const messageTypeListService = () => {
    return request.get('/message/typeList')
}
//申请状态集（当消息类型为申请时需要）
export const applicationStateListService = () => {
    return request.get('/message/application/stateList')
}
//取出申请application，其中当消息类型为申请时，参数context时application的id
export const applicationService = (content) => {
    return request.get('/message/getApplication',{params:{content:content}})
}
//处理申请，即修改为rejected，passed，waiting之一
export const applicationHandleService = (applicationId,toState) => {
    const params = new URLSearchParams()
    params.append("applicationId",applicationId);
    params.append("toState",toState);
    return request.put('/message/handleApplication',params)
}

//当前用户发送的申请列表
export const applicationListService = (params) => {
    return request.get("/message/getApplicationList",{params:params})
}

//发送申请
export const applyService = (newRole) => {
    const params = new URLSearchParams();
    console.log(newRole);
    params.append('newRole',newRole);
    return request.post("/message/apply",params)
}

//撤回申请，并撤回申请所产生的消息
export const withdrawApplyService = (applicationId) => {
    return request.delete('/message/application/withdraw',{params:{applicationId}})
}

//消息列表
export const messageListService = (params) => {
    return request.get('/message/list',{params:params})
}

//指定id阅读消息，即标记已读
export const messageReadSerive = (messageId) => {
    const params = new URLSearchParams()
    params.append("messageId",messageId)
    return request.put('/message/reading',params)
}
//指定id删除已读消息
export const messageDeleteServie = (messageId) => {

    return request.delete('/message/delete',{params:{messageId}})
}

